<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>ES5中的Object.defineProperty</p>
    <label>年龄：</label>
    <input type="text" id="input" oninput="getVal()">
    <p>输入框的内容：<span id="content"></span></p>
    <script>
        // defineProperty 是Object中自带的方法，所有的对象都有
        let person = {name: 'Pony', age: 18};
        let age = person.age;
        let oSpan = document.querySelector('#content');
        Object.defineProperty(person, 'age', {
            // configurable: false, // 能否删除
            // writable: false // 能否修改
            get() {
                console.log(11111);
                return age
            },
            set(val) {
                console.log('我被赋值了，赋的值是：',val);
                oSpan.innerHTML = val;
                return val
            }
        })

        console.log(person.age);

        function getVal() {
            let e = event;
            person.age = e.target.value;
        }
    </script>
</body>
</html>